const { createService, removeService, updateService, findByIdService, findByPageService } = require('../services/settingService');
const AppError = require('../utils/AppError');
const Controller = require('../utils/Controller');
const { toi } = require('../utils/tools');

class SettingController extends Controller {
	async create(req, res, next) {
		res.send('创建');
	}

	async update(req, res, next) {
		const schema = req.joi.object({
			avatar: req.joi.string(),
			siteTitle: req.joi.string(),
			github: req.joi.string(),
			qq: req.joi.string(),
			qqQrCode: req.joi.string(),
			weixin: req.joi.string(),
			weixinQrCode: req.joi.string(),
			mail: req.joi.string(),
			icp: req.joi.string(),
			githubName: req.joi.string(),
			favicon: req.joi.string()
		});
		const { error: failed } = schema.validate(req.body);
		if (failed) return next(new AppError(failed, 400));

		await toi(updateService(req.body), res, next);
	}

	async findInfo(req, res, next) {
		await toi(findByPageService(), res, next);
	}
}

module.exports = new SettingController();
